#!ipxe

# Fedora CoreOS
# https://getfedora.org/coreos/
# https://github.com/coreos/coreos-installer/blob/master/README.md#installing-from-pxe

goto ${menu}

:coreos
set os {{ releases.coreos.name }}
set os_arch ${arch}
iseq ${os_arch} x86_64 && set os_arch x86_64 ||
iseq ${os_arch} arm64 && set os_arch aarch64 ||
isset ${install_device} || set install_device /dev/sda
isset ${ignition_url} || set ignition_url skip
menu ${os} - ${os_arch}
item --gap ${os}:
{% for item in releases.coreos.versions %}
item {{ item.code_name }} ${space} ${os} {{ item.name }}
{% endfor %}
item install_dev ${space} Set install device: ${install_device}
item ignition_config ${space} Set ignition config url: ${ignition_url}
choose --default ${core_version} core_version || goto coreos_exit
echo ${cls}
iseq ${core_version} ignition_config && goto ignition_config ||
iseq ${core_version} install_dev && goto install_dev ||
goto core_boot ||
goto coreos_exit

:core_boot
{% for item in releases.coreos.versions %}
iseq ${core_version} {{ item.code_name }} && set coreos_channel {{ item.name }} ||
{% endfor %}
set base_url ${coreos_mirror}/${coreos_base_dir}/${coreos_channel}/builds
set build_version ${core_version}
imgfree
kernel ${base_url}/${build_version}/${os_arch}/fedora-coreos-${build_version}-live-kernel-${os_arch} ip=dhcp rd.neednet=1 coreos.inst.install_dev=${install_device} coreos.inst.ignition_url=${ignition_url} coreos.live.rootfs_url=${base_url}/${build_version}/${os_arch}/fedora-coreos-${build_version}-live-rootfs.${os_arch}.img {{ kernel_params }}
initrd ${base_url}/${build_version}/${os_arch}/fedora-coreos-${build_version}-live-initramfs.${os_arch}.img
boot
goto coreos_exit

:install_dev
echo -n Please set desired install device:  && read install_device
clear menu
goto coreos

:ignition_config
echo -n Please set Ignition Configuration URL:  && read ignition_url
clear menu
goto coreos

:coreos_exit
clear menu
exit 0
